package com.wxdc.nmgyt.nmgytwydc.activity;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.wxdc.nmgyt.nmgytwydc.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/3/30.
 */

public class zqtest extends BaseActivity implements View.OnTouchListener {



    @BindView(R.id.test_second)
    RelativeLayout mTestSecond;
    @BindView(R.id.test_third)
    LinearLayout mTestThird;
    @BindView(R.id.test_first)
    RelativeLayout mTestFirst;
    private int _yDelta;
    int touchHeight,height_px;

    //获取全屏宽高
    public void getAndroiodScreenProperty() {
        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;         // 屏幕宽度（像素）
        int height = dm.heightPixels;       // 屏幕高度（像素）
        float density = dm.density;         // 屏幕密度（0.75 / 1.0 / 1.5）
        int densityDpi = dm.densityDpi;     // 屏幕密度dpi（120 / 160 / 240）
        // 屏幕宽度算法:屏幕宽度（像素）/屏幕密度
        int screenWidth = (int) (width / density);  // 屏幕宽度(dp)
        touchHeight = (int) (height / density);// 屏幕高度(dp)
        height_px = height;

        Log.d("h_bl", "屏幕宽度（像素）：" + width);
        Log.d("h_bl", "屏幕高度（像素）：" + height);
        Log.d("h_bl", "屏幕密度（0.75 / 1.0 / 1.5）：" + density);
        Log.d("h_bl", "屏幕密度dpi（120 / 160 / 240）：" + densityDpi);
        Log.d("h_bl", "屏幕宽度（dp）：" + screenWidth);
        Log.d("h_bl", "屏幕高度（dp）：" + touchHeight);
    }

    @Override
    protected int getLayout() {
        return R.layout.zq_test;
    }

    @Override
    protected void initInject() {

    }

    @Override
    public void showError(String msg) {

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zq_test);
        ButterKnife.bind(this);
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mTestThird.getLayoutParams();
        layoutParams.leftMargin = 0;
        layoutParams.topMargin = 0;
        layoutParams.bottomMargin = 0;
        layoutParams.rightMargin = 0;
        mTestThird.setLayoutParams(layoutParams);
        mTestThird.setOnTouchListener(this);
    }

    public boolean onTouch(View view, MotionEvent event) {
        final int Y = (int) event.getRawY();
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view
                        .getLayoutParams();
                _yDelta = Y - lParams.topMargin;
                break;
            case MotionEvent.ACTION_UP:
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                break;
            case MotionEvent.ACTION_POINTER_UP:
                break;
            case MotionEvent.ACTION_MOVE:
                getAndroiodScreenProperty();
                RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view
                        .getLayoutParams();
                         Log.i("tag", "你点了第" + touchHeight + "---张轮播图----------"+height_px);

                if ((Y - _yDelta) > 0 && (Y - _yDelta) < (height_px-200) ){
                    layoutParams.topMargin = Y - _yDelta;
                    RelativeLayout.LayoutParams layout = (RelativeLayout.LayoutParams) mTestSecond.getLayoutParams();
                    layout.height = Y - _yDelta-10;
                    mTestSecond.setLayoutParams(layout);
                }
                layoutParams.rightMargin = 0;
                layoutParams.bottomMargin = 0;
                view.setLayoutParams(layoutParams);
                break;
        }
        mTestFirst.invalidate();
        return true;
    }




}
